package com.woniuxy.java106crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.java106crm.entity.Leads;
import com.woniuxy.java106crm.mapper.MarketingMapper;
import com.woniuxy.java106crm.request.ResPage;
import com.woniuxy.java106crm.service.MarketingService;
import com.woniuxy.java106crm.vo.marketing.LeadsPageSizeVo;
import com.woniuxy.java106crm.vo.marketing.LeadsStateVo;
import com.woniuxy.java106crm.vo.marketing.LeadsVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MartektingServiceImpl implements MarketingService {
    @Resource
    private MarketingMapper marketingMapper;
    @Override
    public ResPage<List<Leads>> findAll(LeadsPageSizeVo leadsPageSizeVo) {
        PageHelper.startPage(leadsPageSizeVo.getPage(), leadsPageSizeVo.getSize());
        //
        List<Leads> leadsList = marketingMapper.findAll(leadsPageSizeVo);
        // 获取分页信息
        PageInfo<Leads> pageInfo = new PageInfo<>(leadsList);
        //
        ResPage<List<Leads>> resPage = new ResPage<>();
        resPage.setCurPage(pageInfo.getPageNum());
        resPage.setSize(pageInfo.getPageSize());
        resPage.setTotal(pageInfo.getTotal());
        resPage.setTotalPage(pageInfo.getPages());
        resPage.setData(pageInfo.getList());
        return resPage;
    }

    @Override
    public boolean addLeads(Leads leads) {
        return marketingMapper.addLeads(leads);
    }

    @Override
    public boolean updateLeads(Leads leads) {
        return marketingMapper.updateLeads(leads);
    }

    @Override
    public boolean delLeadsById(int id) {
        return marketingMapper.delLeadsById(id);
    }

    @Override
    public Leads findLeadsById(int id) {
        return marketingMapper.findLeadsById(id);
    }

    @Override
    public boolean updateAppointor(LeadsVo leadsVo) {
        return marketingMapper.updateAppointor(leadsVo);
    }

    @Override
    public String selectByAppointTime(int id) {
        return marketingMapper.selectByAppointTime(id);
    }

    @Override
    public boolean updateStatById(LeadsStateVo leadsStateVo) {
        return marketingMapper.updateStatById(leadsStateVo);
    }

    @Override
    public int haveRole(int uid) {
        return marketingMapper.haveRole(uid);
    }
}
